import {DataTypes, Model} from "sequelize";
import sequelize from "@/databases";
import {error} from "@/utils/responseUtils";

class UsersModel extends Model {

}

UsersModel.init({
    id: {
        type: DataTypes.BIGINT,
        autoIncrement: true,
        primaryKey: true,
        allowNull: false,
        comment: "id"
    },
    userName: DataTypes.STRING,
    accountNumber: DataTypes.STRING,
    password: DataTypes.STRING,
    age: DataTypes.INTEGER,
    gender: DataTypes.INTEGER,
    icon: DataTypes.STRING,
    role:DataTypes.INTEGER,
    tags:DataTypes.STRING,
    desc:DataTypes.STRING,
    classId:DataTypes.INTEGER,
}, {
    sequelize,
    validate: {
        // async bothCoordsOrNone() {
        //     const userOfUserName = await UsersModel.findOne({where: {userName: this.userName}})
        //     if (userOfUserName !== null) {
        //         error("昵称已存在")
        //     }
        //     const userOfAccount = await UsersModel.findOne({where: {accountNumber: this.accountNumber}})
        //     if (userOfAccount !== null) {
        //         error("账号已存在")
        //     }
        // }
    },
    tableName: 'user'
})
export default UsersModel